import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)
// 引入封装好的模块
import menu from './modules/menu'
import role from './modules/role'
import manger from './modules/manger'
import cate from './modules/cate'
import specs from './modules/specs'
import goods from './modules/goods'
import banner from './modules/banner'
import member from './modules/member'
import seck from './modules/seck'

export default new Vuex.Store({
  state: {
    userInfo:sessionStorage.getItem('userinfo')?JSON.parse(sessionStorage.getItem('userinfo')):null
      
  },
  getters:{
    getuserInfo(state){
      return state.userInfo
    }
  },
  mutations: {
    REQ_USERINFO(state,payload){
      if (payload) {
        // 如果传递的参数为真，就修改数据参数，存储到状态管理中
        state.userInfo = payload
        sessionStorage.setItem('userinfo',JSON.stringify(payload))
      }else{
        // 一处会话存储
        sessionStorage.removeItem('userinfo')

      }
    }
  },
  actions: {
    // 修改用户信息
    changeUserAction({commit},payload){
      commit('REQ_USERINFO',payload)
    }
  },
  modules: {
    menu,
    role,
    manger,
    cate,
    specs,
    goods,
    banner,
    member,
    seck
  }
})
